package cn.mdruby.baselibrary.utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Went_Gone on 2018/4/28.
 */

public class DateUtil {
    public static String getDate(long dateLong,String type){
        SimpleDateFormat format = new SimpleDateFormat(type);
        Date date = new Date(dateLong);
        return format.format(date);
    }
    /**
    * 将短时间格式字符串转换为时间 yyyy-MM-dd
    *
    * @param strDate
    * @return
    */
    public static Date strToDate(String strDate) {
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
     }

     public static long toLong(String strDate){
         Date date = strToDate(strDate);
         return date.getTime();
     }
}
